let { pool } = require("../../config/mysql_config");

module.exports = {
  add: function (params, callback) {
    let sql = 'INSERT INTO user (avatarurl, name, age, sex) VALUES (?, ?, ?, ?);';
    // pool.getConnection(function (err, connection) {
    // if (err) throw err;
    let sqlparam = [
      params.avatarurl ? params.avatarurl : "",
      params.name ? params.name : "wzd",
      params.age ? params.age : "24",
      params.sex ? params.sex : 1
    ]
    pool.query(sql, sqlparam, function (err, rows) {
      if (err) {
        throw err;
      } else {
        callback(rows);
      }
    });
    //   connection.release();
    // });
  },
  query: function (params, callback) { // users表中查询指定user操作
    let sql = "SELECT * FROM user;";
    // let sql = "SELECT * FROM users WHERE id = ?;",
    let { id } = params;
    let sqlparam = [id];
    pool.query(sql, function (error, result) {
      console.log(result)
      if (error) throw error;
      callback(result[0]);
    });
  },
  upload_info(params, callback){
    console.log(params)
  },
  upload_avatar(params, callback){
    console.log(111)
    console.log(params)
  }
}